import { defHttp } from "/@/utils/http/axios"
import { Modal } from "ant-design-vue"

enum Api {
  listMobileMenu = "/system-service/mobileMenu/list",
  getMobileMenu = "/system-service/mobileMenu/get",
  saveMobileMenu = "/system-service/mobileMenu/save",
  updateMobileMenu = "/system-service/mobileMenu/update",
  deleteMobileMenu = "/system-service/mobileMenu/delete",
  batchDeleteMobileMenu = "/system-service/mobileMenu/batchDelete",

  saveGroup = "/system-service/mobileMenu/saveGroup",
  updateGroup = "/system-service/mobileMenu/updateGroup",
  batchDeleteGroup = "/system-service/mobileMenu/batchDeleteGroup",
  deleteGroup = "/system-service/mobileMenu/deleteGroup",
}

export const getMobileMenu = (params) => {
  return defHttp.get({ url: Api.getMobileMenu, params })
}

export const listMobileMenu = (params) => {
  return defHttp.get({ url: Api.listMobileMenu, params })
}

export const saveOrUpdateMobileMenu = (params, isUpdate) => {
  const url = isUpdate ? Api.updateMobileMenu : Api.saveMobileMenu
  return defHttp.post({ url: url, params })
}

export const deleteMobileMenu = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.deleteMobileMenu, data: params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess()
  })
}

export const batchDeleteMobileMenu = (params, handleSuccess) => {
  Modal.confirm({
    title: "确认删除",
    content: "是否删除选中数据",
    okText: "确认",
    cancelText: "取消",
    onOk: () => {
      return defHttp.delete({ url: Api.batchDeleteMobileMenu, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess()
      })
    },
  })
}

export const saveOrUpdateGroup = (params, isUpdate) => {
  const url = isUpdate ? Api.updateGroup : Api.saveGroup
  return defHttp.post({ url: url, params })
}

export const deleteGroup = (params, handleSuccess) => {
  Modal.confirm({
    title: `确认删除${params.name}`,
    content: "是否删除选中数据",
    okText: "确认",
    cancelText: "取消",
    onOk: () => {
      return defHttp.delete({ url: Api.deleteGroup, data: { id: params.id } }, { joinParamsToUrl: true }).then(() => {
        handleSuccess()
      })
    },
  })
}

export const batchDeleteGroup = (params, handleSuccess) => {
  Modal.confirm({
    title: `确认删除`,
    content: "是否删除选中数据",
    okText: "确认",
    cancelText: "取消",
    onOk: () => {
      return defHttp.delete({ url: Api.batchDeleteGroup, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess()
      })
    },
  })
}
